﻿
/*****************************************************************************
*日期资料
*感谢：万年历计算的代码是从网上获得，具体出处已经不得而知，但仍然要
*       感谢本代码的编写者。
*代码整理及功能补充：wangshun 
*描述：本文件中的代码主要实现了万年历的计算，以及工作日设置、日历新
建功能。
*****************************************************************************/
//比较高深，看不懂，只知道这数组是为算阴历用的
var lunarInfo = new Array(
0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2,
0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977,
0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970,
0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950,
0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557,
0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950, 0x06aa0,
0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0,
0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6,
0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570,
0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0,
0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5,
0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930,
0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530,
0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45,
0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0)
//阳历月
var solarMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var Gan = new Array("甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸");
var Zhi = new Array("子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥");
var Animals = new Array("鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪");
var solarTerm = new 
Array("小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至"
, "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至")
var sTermInfo = new Array(0, 21208, 42467, 63836, 85337, 107014, 128867, 150921, 173149, 195551, 218072, 240693, 263343, 285989, 308563, 331033, 353350, 375494, 397447, 419210, 440795, 462224, 483532, 504758)
var nStr1 = new Array('日', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十')
var nStr2 = new Array('初', '十', '廿', '卅', '　')
var monthName = new Array("1 月", "2 月", "3 月", "4 月", "5 月", "6 月", "7 月", "8 月", "9月", "10 月", "11 月", "12月");
var m_bShowDetail = false;

//国历节日 *表示放假日
//"0518 晓丹生日",
var sFtv = new Array(
					"0101*元旦",
					"0214 情人节",
					"0308 妇女节",
					"0312 植树节",
					"0315 消费者权益日",
					"0401 愚人节",
					"0501 劳动节",
					"0504 青年节",
					"0512 护士节",
					"0601 儿童节",
					"0701 建党节 香港回归纪念",
					"0801 建军节",
					"0808 父亲节",
					"0909 毛泽东逝世纪念",
					"0910 教师节",
					"0928 孔子诞辰",
					"1001*国庆节",
					"1006 老人节",
					"1024 联合国日",
					"1112 孙中山诞辰纪念",
					"1220 澳门回归纪念",
					"1225 圣诞节",
					"1226 毛泽东诞辰纪念")

//农历节日 *表示放假日
var lFtv = new Array(
					"0101*春节",
					"0115 元宵节",
					"0505 端午节",
					"0707 七夕情人节",
					"0815 中秋节",
					"0909 重阳节",
					"1224 小年",
					"0100*除夕"
					)

//某月的第几个星期几
var wFtv = new Array(
					"0520 母亲节",
					"0716 合作节",
					"0730 被奴役国家周"
					)


var m_PlaydayColor = "#D5D5D5";       //休息日单元格的背景颜色         
var m_DefaultBgColor = "#FFFFFF";     //日期单元格缺省背景颜色
var m_SelectItemColor = "#6495ED";    //选中的日期单元格的背景颜色
var m_WorkdayColor = "#FFFFFF";       //工作日单元格的背景颜色
var m_csPlayday = "Playday";
var m_csWorkday = "Workday";
var m_csDayStateChanged = "DayStateChanged";
var m_csWorkTimeChanged = "WorkTimeChanged";
var m_xmlDefaultInfo;    //暂时无用
var m_xmlUpdateInfo;     //暂时无用
var m_XMLHttp;           //AJAX XMLHttpRequest对象
var m_sResponseURL = "GeoWorkday.aspx"    //服务端响应页面
var m_ResponseXML;                      //XMLDocument对象，以月为单位存储工作日信息
var m_bResponseOK;                      //服务端相应是否成功
var m_sCurrentCalendar;                 //当前日历名称，即日历名称下拉列表中当前被选中的项

var m_iCurYear;                         //当前年
var m_iCurMonth;                        //当前月
var m_argObject;                        //在新建日历对话框与本页面之间传递参数的Object对象
var m_xmlUpdatedCells;                  //缓存工作日状态被改变了的日期单元格，暂时无用
/*****************************************************************************
日期计算
*****************************************************************************/

//====================================== 传回农历 y年的总天数
function lYearDays(y) {
    var i, sum = 348
    for (i = 0x8000; i > 0x8; i >>= 1) sum += (lunarInfo[y - 1900] & i) ? 1 : 0
    return (sum + leapDays(y))
}

//====================================== 传回农历 y年闰月的天数
function leapDays(y) {
    if (leapMonth(y)) return ((lunarInfo[y - 1900] & 0x10000) ? 30 : 29)
    else return (0)
}

//====================================== 传回农历 y年闰哪个月 1-12 , 没闰传回 0
function leapMonth(y) {
    return (lunarInfo[y - 1900] & 0xf)
}

//====================================== 传回农历 y年m月的总天数
function monthDays(y, m) {
    return ((lunarInfo[y - 1900] & (0x10000 >> m)) ? 30 : 29)
}

//====================================== 算出农历, 传入日期物件, 传回农历日期物件
//                                       该物件属性有 .year .month .day .isLeap .yearCyl .dayCyl .monCyl
function Lunar(objDate) {

    var i, leap = 0, temp = 0
    var baseDate = new Date(1900, 0, 31)
    var offset = (objDate - baseDate) / 86400000

    this.dayCyl = offset + 40
    this.monCyl = 14

    for (i = 1900; i < 2050 && offset > 0; i++) {
        temp = lYearDays(i)
        offset -= temp
        this.monCyl += 12
    }

    if (offset < 0) {
        offset += temp;
        i--;
        this.monCyl -= 12
    }

    this.year = i
    this.yearCyl = i - 1864

    leap = leapMonth(i) //闰哪个月
    this.isLeap = false

    for (i = 1; i < 13 && offset > 0; i++) {
        //闰月
        if (leap > 0 && i == (leap + 1) && this.isLeap == false)
        { --i; this.isLeap = true; temp = leapDays(this.year); }
        else
        { temp = monthDays(this.year, i); }

        //解除闰月
        if (this.isLeap == true && i == (leap + 1)) this.isLeap = false

        offset -= temp
        if (this.isLeap == false) this.monCyl++
    }

    if (offset == 0 && leap > 0 && i == leap + 1)
        if (this.isLeap)
        { this.isLeap = false; }
        else
        { this.isLeap = true; --i; --this.monCyl; }

    if (offset < 0) { offset += temp; --i; --this.monCyl; }

    this.month = i
    this.day = offset + 1
}

//==============================传回国历 y年某m+1月的天数
function solarDays(y, m) {
    if (m == 1)
        return (((y % 4 == 0) && (y % 100 != 0) || (y % 400 == 0)) ? 29 : 28)
    else
        return (solarMonth[m])
}
//============================== 传入 offset 传回干支, 0=甲子
function cyclical(num) {
    return (Gan[num % 10] + Zhi[num % 12])
}

//============================== 月历属性
function calElement(sYear, sMonth, sDay, week, lYear, lMonth, lDay, isLeap, cYear, cMonth, cDay) {

    this.isToday = false;
    //国历
    this.sYear = sYear;
    this.sMonth = sMonth;
    this.sDay = sDay;
    this.week = week;
    //农历
    this.lYear = lYear;
    this.lMonth = lMonth;
    this.lDay = lDay;
    this.isLeap = isLeap;
    //干支
    this.cYear = cYear;
    this.cMonth = cMonth;
    this.cDay = cDay;

    this.color = '';

    this.lunarFestival = ''; //农历节日
    this.solarFestival = ''; //国历节日
    this.solarTerms = ''; //节气

}

//===== 某年的第n个节气为几日(从0小寒起算)
function sTerm(y, n) {
    var offDate = new Date((31556925974.7 * (y - 1900) + sTermInfo[n] * 60000) +
					 Date.UTC(1900, 0, 6, 2, 5))
    return (offDate.getUTCDate())
}

//============================== 传回月历物件 (y年,m+1月)
function calendar(y, m) {
    var sDObj, lDObj, lY, lM, lD = 1, lL, lX = 0, tmp1, tmp2
    var lDPOS = new Array(3)
    var n = 0
    var firstLM = 0

    sDObj = new Date(y, m, 1)            //当月一日日期

    this.length = solarDays(y, m)    //国历当月天数
    this.firstWeek = sDObj.getDay()    //国历当月1日星期几


    for (var i = 0; i < this.length; i++) {

        if (lD > lX) {
            sDObj = new Date(y, m, i + 1)    //当月一日日期
            lDObj = new Lunar(sDObj)     //农历
            lY = lDObj.year           //农历年
            lM = lDObj.month          //农历月
            lD = lDObj.day            //农历日
            lL = lDObj.isLeap         //农历是否闰月
            lX = lL ? leapDays(lY) : monthDays(lY, lM) //农历当月最後一天

            if (n == 0) firstLM = lM
            lDPOS[n++] = i - lD + 1
        }

        //sYear,sMonth,sDay,week,
        //lYear,lMonth,lDay,isLeap,
        //cYear,cMonth,cDay
        this[i] = new calElement(y, m + 1, i + 1, nStr1[(i + this.firstWeek) % 7],
                               lY, lM, lD++, lL,
                               cyclical(lDObj.yearCyl), cyclical(lDObj.monCyl), cyclical(lDObj.dayCyl++))


        //      if((i+this.firstWeek)%7==0)   this[i].color = 'red'  //周日颜色
        //      if((i+this.firstWeek)%14==13) this[i].color = 'green'  //周休二日颜色
    }

    //节气
    tmp1 = sTerm(y, m * 2) - 1
    tmp2 = sTerm(y, m * 2 + 1) - 1
    this[tmp1].solarTerms = solarTerm[m * 2]
    this[tmp2].solarTerms = solarTerm[m * 2 + 1]
    if (m == 3) this[tmp1].color = 'red' //清明颜色

    //国历节日
    for (i in sFtv)
        if (sFtv[i].match(/^(\d{2})(\d{2})([\s\*])(.+)$/))
            if (Number(RegExp.$1) == (m + 1)) {
                this[Number(RegExp.$2) - 1].solarFestival += RegExp.$4 + ' '
                if (RegExp.$3 == '*') this[Number(RegExp.$2) - 1].color = 'black';
            }

    //月周节日
    for (i in wFtv)
        if (wFtv[i].match(/^(\d{2})(\d)(\d)([\s\*])(.+)$/))
            if (Number(RegExp.$1) == (m + 1)) {
                tmp1 = Number(RegExp.$2)
                tmp2 = Number(RegExp.$3)
                this[((this.firstWeek > tmp2) ? 7 : 0) + 7 * (tmp1 - 1) + tmp2 - this.firstWeek].solarFestival += RegExp.$5 + ' '
            }

    //农历节日
    for (i in lFtv)
        if (lFtv[i].match(/^(\d{2})(.{2})([\s\*])(.+)$/)) {
            tmp1 = Number(RegExp.$1) - firstLM
            if (tmp1 == -11) tmp1 = 1
            if (tmp1 >= 0 && tmp1 < n) {
                tmp2 = lDPOS[tmp1] + Number(RegExp.$2) - 1
                if (tmp2 >= 0 && tmp2 < this.length) {
                    this[tmp2].lunarFestival += RegExp.$4 + ' '
                    if (RegExp.$3 == '*') this[tmp2].color = 'red'
                }
            }
        }

    //黑色星期五
    //   if((this.firstWeek+12)%7==5)
    //      this[12].solarFestival += '黑色星期五 '

    //今日
    if (y == tY && m == tM) this[tD - 1].isToday = true;

}

//====================== 中文日期
function cDay(d) {
    var s;

    switch (d) {
        case 10:
            s = '初十'; break;
        case 20:
            s = '二十'; break;
            break;
        case 30:
            s = '三十'; break;
            break;
        default:
            s = nStr2[Math.floor(d / 10)];
            s += nStr1[d % 10];
    }
    return (s);
}

///////////////////////////////////////////////////////////////////////////////

var cld;

function drawCld(SY, SM) {
    var i, sD, s, size;
    cld = new calendar(SY, SM);

    if (SY > 1874 && SY < 1909) yDisplay = '光绪' + (((SY - 1874) == 1) ? '元' : SY - 1874)
    if (SY > 1908 && SY < 1912) yDisplay = '宣统' + (((SY - 1908) == 1) ? '元' : SY - 1908)
    if (SY > 1911 && SY < 1950) yDisplay = '民国' + (((SY - 1911) == 1) ? '元' : SY - 1911)
    if (SY > 1949) yDisplay = '共和国' + (((SY - 1949) == 1) ? '元' : SY - 1949)

    GZ.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + yDisplay + '年 农历' +

	cyclical(SY - 1900 + 36) + '年 &nbsp;&nbsp;【' + Animals[(SY - 4) % 12] + '】年';

    //以今天的日期作为背景显示在后面
    //YMBG.innerHTML = "&nbsp;" + SY + 
    //"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + monthName[SM];

    var gObj;
    for (i = 0; i < 42; i++) {

        sObj = eval('SD' + i);
        lObj = eval('LD' + i);
        gObj = eval('GD' + i);

        sObj.className = '';
        lObj.className = "";
        gObj.title = "";
        gObj.style.backgroundColor = '';
        sD = i - cld.firstWeek;

        if (sD > -1 && sD < cld.length) { //日期内

            sObj.innerHTML = sD + 1;
            sObj.style.fontFamily = "Verdana";
            sObj.style.fontSize = "13px";
            if (cld[sD].isToday) {
                //sObj.innerHTML = "&nbsp;" + sObj.innerHTML + "&nbsp;";
                sObj.className = 'todayColor'; //今日颜色
                lObj.className = 'todayColor';
                gObj.title = "今天";
            }

            sObj.style.color = cld[sD].color; //国定假日颜色

            if (cld[sD].lDay == 1) //显示农历月
                lObj.innerHTML = '<b>' + (cld[sD].isLeap ? '闰' : '') + cld[sD].lMonth + '月' +
								(monthDays(cld[sD].lYear, cld[sD].lMonth) == 29 ? '小' : '大') + '</b>';
            else //显示农历日
                lObj.innerHTML = cDay(cld[sD].lDay);

            s = cld[sD].lunarFestival;
            if (s.length > 0) { //农历节日
                if (s.length > 6) s = s.substr(0, 3) + '…';
                s = s.fontcolor('blue');
            }
            else { //国历节日
                s = cld[sD].solarFestival;
                if (s.length > 0) {
                    size = (s.charCodeAt(0) > 0 && s.charCodeAt(0) < 128) ? 8 : 4;
                    if (s.length > size + 2) s = s.substr(0, size - 1) + '…';
                    s = s.fontcolor('blue');
                }
                else { //廿四节气
                    s = cld[sD].solarTerms;
                    if (s.length > 0) s = s.fontcolor('limegreen');
                }
            }
            if (s.length > 0) lObj.innerHTML = s;

            var iDay = sD + 1;
            var iM = SM + 1;
            //获得日期单元格对应的周天
            var iWeekDay = GetWeekDayByCellIndex(i);
            //设置日期单元格元素的各个属性
            GeoWD_SetDateCellState(SY, SM, iDay, iWeekDay, gObj);

            gObj.setAttribute("ValidDateCell", "true");
            //记录单元格对应的日期
            var sDate = SY + "-" + iM + "-" + iDay;
            gObj.setAttribute("DateValue", sDate);
        }
        else { //非日期
            sObj.innerHTML = '';
            lObj.innerHTML = '';
            gObj.setAttribute("ValidDateCell", "false");

            gObj.style.backgroundColor = m_DefaultBgColor;
        }
    }
}

function GetWeekDayByCellIndex(CellIndex) {
    //根据日期单元格的索引获得本单元格对应的周天
    var WeekDay = CellIndex % 7;
    return WeekDay;
}
function GeoWD_SetDateCellState(SY, SM, SD, Weekday, DateCell) {
    //首先加上标识，表明本日期单元格的工作日状态没有被修改过
    DateCell.setAttribute(m_csDayStateChanged, "false");
    //获得当前用户当前选中的日历信息
    GeoWD_ClearWTChangedStyle(DateCell);
    //分别设置工作日和休息日日期单元格的背景色
    if (GeoWD_IsPlayday(SY, SM, SD, Weekday) == true)
        GeoWD_SetDayStateAndColor(DateCell, m_csPlayday, m_PlaydayColor, m_csPlayday);
    else {
        GeoWD_SetDayStateAndColor(DateCell, m_csWorkday, m_DefaultBgColor, m_csWorkday);
        GeoWD_SetWorkTimeAttrs(DateCell);
    }

    //GeoWD_InitUpdatedCells(SY,SM,SD,DateCell);
}
function GeoWD_InitUpdatedCells(SY, SM, SD, DateCell) {

    if (m_xmlUpdatedCells == null) return;

    var docElement = m_xmlUpdatedCells.documentElement;
    if (docElement == null) return;
    if (docElement.hasChildNodes == false) return;

    var iM = SM + 1;
    var sXPath = './DateCell[@Date="' + SY + "-" + iM + "-" + SD + '"]';

    var DateCellNode = docElement.selectSingleNode(sXPath);

    if (DateCellNode != null) {
        GeoWD_ResetDayStates(DateCell, DateCellNode);
        //GeoWD_ResetWorkTimes(DateCell,DateCellNode);
    }

}
function GeoWD_InitDateCellByXML(xmlDoc, SY, SM, SD, DateCell) {
    var bGetted = false;
    var iM = SM + 1;

    var curWorkDayInfosNode = xmlDoc.selectSingleNode('WorkDayInfo/WorkDayInfos[@name="' + m_sCurrentCalendar + '"]');

    if (curWorkDayInfosNode == null) return bGetted;
    var WorkDayNode = GeoWD_GetWorkDayNode(SY, SM, SD, curWorkDayInfosNode);
    var WorkInfoNodeTime;

    if (WorkDayNode == null) {
        //经过一层层的寻找后，还没有找到，那么就认为这一日是工作日，下一步就是要求得工作日段
        //但是工作时段的信息也没有定义，那么就认为在m_xmlUpdateInfo中，这一日的信息不存在了
        WorkInfoNodeTime = GeoWD_WorkTimeDefined(curWorkDayInfosNode);
        if (WorkInfoNodeTime != null) {
            GeoWD_SetDayStateAndColor(DateCell, m_csWorkday, m_DefaultBgColor, m_csWorkday);
            GeoWD_SetWorkTimeByNode(DateCell, WorkInfoNodeTime);
            bGetted = true;
        }
    }
    else {
        var sDayState = WorkDayNode.getAttribute("State");
        var iDayState = parseInt(sDayState);

        if (iDayState == 4 || iDayState == 12 || iDayState == 20) {
            GeoWD_SetDayStateAndColor(DateCell, m_csWorkday, m_DefaultBgColor, m_csWorkday);
            WorkInfoNodeTime = GeoWD_GetWorkTimeParentNode(curWorkDayInfosNode, WorkDayNode);
            GeoWD_SetWorkTimeByNode(DateCell, WorkInfoNodeTime);
        }
        else if (iDayState == 2 || iDayState == 10 || iDayState == 18) {
            GeoWD_SetDayStateAndColor(DateCell, m_csPlayday, m_PlaydayColor, m_csPlayday);
        }
        bGetted = true;
    }

    return bGetted;
}
function GeoWD_GetWorkTimeParentNode(WorkDayInfosNode, WorkDayNode) {
    var sXPath = "./WorkTime";
    var oParentNode = WorkDayNode.parentNode;
    var WorkTimeNode = oParentNode.selectSingleNode(sXPath);
    if (WorkTimeNode == null)
        oParentNode = GeoWD_WorkTimeDefined(WorkDayInfosNode);

    return oParentNode;
}
function GeoWD_SetWorkTimeByNode(DateCell, WorkInfoNodeTime) {
    var WorkTimeNodes = WorkInfoNodeTime.selectNodes('./WorkTime');
    var WorkTimeNode;
    var sBeginTime, sEndTime, j;
    var sDefaultBeginTime, sDefaultEndTime;
    for (var i = 0; i < WorkTimeNodes.length; i++) {
        j = i + 1;
        WorkTimeNode = WorkTimeNodes[i];

        sBeginTime = "BeginTime" + j;
        sEndTime = "EndTime" + j;
        sDefaultBeginTime = "DefaultBeginTime" + j;
        sDefaultEndTime = "DefaultEndTime" + j;

        DateCell.setAttribute(sBeginTime, WorkTimeNode.getAttribute("BeginTime"));
        DateCell.setAttribute(sEndTime, WorkTimeNode.getAttribute("EndTime"));

        DateCell.setAttribute(sDefaultBeginTime, WorkTimeNode.getAttribute("BeginTime"));
        DateCell.setAttribute(sDefaultEndTime, WorkTimeNode.getAttribute("EndTime"));
    }
}
function GeoWD_SetDayStateAndColor(DateCell, DayState, sColor, DefaultDayState) {
    //设置日期单元格的工作日状态(DayState)和背景颜色
    if (DefaultDayState != null) DateCell.setAttribute("DefaultDayState", DefaultDayState);

    DateCell.setAttribute("DayState", DayState);
    DateCell.setAttribute("OldDayState", DayState);
    DateCell.style.backgroundColor = sColor;
    DateCell.setAttribute("OldBgColor", sColor);

}
function GeoWD_WeekDayDefined(curWorkDayInfosNode) {
    var sXPath = './WorkDayInfo/WorkDay[not (@Year) and not (@Month) and not (@Day) and @WeekDay]'
    var WeekDayNode = curWorkDayInfosNode.selectSingleNode(sXPath);
    return WeekDayNode;
}
function GeoWD_WorkTimeDefined(curWorkDayInfosNode) {
    var sXPath = './WorkDayInfo[not (WorkDay) and WorkTime]'
    var WorkTimeInfoNode = curWorkDayInfosNode.selectSingleNode(sXPath);
    return WorkTimeInfoNode;
}
function GeoWD_GetWorkDayNode(SY, SM, SD, curWorkDayInfosNode) {
    var iM = SM + 1;
    var sXPath = './WorkDayInfo/WorkDay[@Year="' + SY + '" and @Month="' + iM + '" and @Day="' + SD + '"]';

    var WorkDayNode = curWorkDayInfosNode.selectSingleNode(sXPath);
    if (WorkDayNode == null) {
        sXPath = './WorkDayInfo/WorkDay[not (@Year) and @Month="' + iM + '" and @Day="' + SD + '"]';
        WorkDayNode = curWorkDayInfosNode.selectSingleNode(sXPath);
        if (WorkDayNode == null) {
            sXPath = './WorkDayInfo/WorkDay[not (@Year) and not (@Month) and @Day="' + SD + '"]';
            WorkDayNode = curWorkDayInfosNode.selectSingleNode(sXPath);
            if (WorkDayNode == null) {
                //在“星期制”里面找
                var oDate = new Date(SY, SM, SD);
                var iDay = oDate.getDay();
                sXPath = './WorkDayInfo/WorkDay[not (@Year) and not (@Month) and not (@Day) and @WeekDay="' + iDay + '"]'

                WorkDayNode = curWorkDayInfosNode.selectSingleNode(sXPath);
            }
        }
    }

    return WorkDayNode;
}
function GeoWD_WorkDayByRange(SY, SM, SD, curWorkDayInfosNode) {

}
function GeoWD_SetWorkTimeAttrs(DateCell) {
    DateCell.setAttribute("BeginTime1", "8:30");
    DateCell.setAttribute("EndTime1", "11:30");
    DateCell.setAttribute("BeginTime2", "14:00");
    DateCell.setAttribute("EndTime2", "17:30");

    DateCell.setAttribute("DefaultBeginTime1", "8:30");
    DateCell.setAttribute("DefaultEndTime1", "11:30");
    DateCell.setAttribute("DefaultBeginTime2", "14:00");
    DateCell.setAttribute("DefaultEndTime2", "17:30");
}

function GeoWD_IsPlayday(y, m, d, weekday) {
    var workdayNode = GetWorkDayInfoNode(y, m, d, weekday);

    if (workdayNode == null) return false;
    var sState = workdayNode.getAttribute("State");
    if (sState == "2") return true;

    return false;
}

function GetWorkDayInfoNode(SY, SM, SD, weekday) {
    var iM = SM + 1;
    var sXPath = "";
    var WorkDayNode = null;
    if (iM) {
        sXPath = 'WorkdayInfo/info[@BeginYear="' + SY + '" and @BeginMonth="' + iM + '" and @BeginDay="' + SD + '"]';
        WorkDayNode = m_ResponseXML.selectSingleNode(sXPath);
    }
    if (WorkDayNode == null) {
        sXPath = "WorkdayInfo/info[@Weekday='" + weekday + "']";
        WorkDayNode = m_ResponseXML.selectSingleNode(sXPath);

    }
    return WorkDayNode;
}
function GeoWD_PlaceZero(aNumber) {
    var sResult;
    if (aNumber < 10)
        sResult = "0" + aNumber;
    else
        sResult = aNumber;

    return sResult;
}

function changeCld() {
    var y, m;
    y = CLD.SY.selectedIndex + 1900;
    m = CLD.SM.selectedIndex;
    drawCld(y, m);
}
function ToToday() {
    var newDate = new Date();
    var sYear = newDate.getFullYear();
    var sMonth = newDate.getMonth();

    var yearSelect = document.getElementById("SY");
    yearSelect.value = sYear;
    var monthSelect = document.getElementById("SM");
    monthSelect.value = sMonth + 1;
    GeoWD_OnYMChange();
}
function GeoWD_OnYMChange(oSource, oEvent, sType) {
    //	GeoWD_GatherUpdates(m_iCurYear,m_iCurMonth);
    //	GeoWD_GetUpdatedCells(m_iCurYear,m_iCurMonth);

    GeoWD_OnSubmit();
    var y, m;
    var yearSelect = document.getElementById("SY");
    y = yearSelect.selectedIndex + 1900;
    var monthSelect = document.getElementById("SM");
    m = monthSelect.selectedIndex;

    m_iCurYear = y;
    m_iCurMonth = m + 1;

    //GeoForm_Output(m_xmlDefaultInfo.xml);
    ShowProgressBar("正在获取工作日信息...");
    GeoWD_GetMonthWorkDayInfo(m_sCurrentCalendar, m_iCurYear, m_iCurMonth, false, "QUERY", OnYMChangeHandler);
}
function GeoWD_ParseResponseResult(response) {
    var arData = response.documentElement;
    if (arData) {
        var sEncodedContent = arData.firstChild.nodeValue;
        var sContent = sEncodedContent.replace(/\$\$\$CART_CDATA_CLOSE\$\$\$/g, "]]>");

        return sContent;
    }
    return null;
}
function OnYMChangeHandler() {
    if (m_XMLHttp.readyState == 4) {
        if (m_XMLHttp.status == 200) {

            if (m_XMLHttp.responseXML) {
                var result = GeoWD_ParseResponseResult(m_XMLHttp.responseXML);
                if (result) {
                    m_ResponseXML = null;
                    if (m_ResponseXML == null) m_ResponseXML = new ActiveXObject("MSXML2.DOMDOCUMENT.6.0");
                    m_ResponseXML.loadXML(result);

                    m_bResponseOK = true;
                    drawCld(m_iCurYear, m_iCurMonth - 1);
                }
            }
            HideProgressBar("就绪！");

        }
        else {
            HideProgressBar("获取工作日信息失败！");
        }
    }
}
var Today = new Date();
var tY = Today.getFullYear();
var tM = Today.getMonth();
var tD = Today.getDate();
//////////////////////////////////////////////////////////////////////////////

var width = 200;
var offsetx = 60;
var offsety = 16;

var x = 0;
var y = 0;
var snow = 0;
var sw = 0;
var cnt = 0;

var dStyle;
document.onmousemove = mEvn;

//显示详细日期资料================================================================
function mOvr(v) {
    if (m_bShowDetail == false) return;
    var s, festival;
    var sObj = eval('SD' + v);
    var d = sObj.innerHTML - 1;

    //sYear,sMonth,sDay,week,
    //lYear,lMonth,lDay,isLeap,
    //cYear,cMonth,cDay

    if (sObj.innerHTML != '') {

        sObj.style.cursor = 'default';

        if (cld[d].solarTerms == '' && cld[d].solarFestival == '' && cld[d].lunarFestival ==

'')
            festival = '';
        else
            festival = '<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR="#CCFFCC"><TR><TD>' +
         '<FONT COLOR="#000000" STYLE="font-size:9pt;">' + cld[d].solarTerms + ' ' + cld[d].solarFestival + ' ' + cld[d].lunarFestival + '</FONT></TD>' +
         '</TR></TABLE>';

        s = '<TABLE WIDTH="130" BORDER=0 CELLPADDING="2" CELLSPACING=0 BGCOLOR="#000066"><TR><TD>' +
         '<TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD ALIGN="right"><FONT COLOR="#ffffff" STYLE="font-size:9pt;">' + cld[d].sYear +
         ' 年 ' + cld[d].sMonth + ' 月 ' + cld[d].sDay +
         '日<br>星期' + cld[d].week + '<br>' +
         '<font color="violet">农历' + (cld[d].isLeap ? '闰 ' : ' ') + cld[d].lMonth + ' 月 ' +
         cld[d].lDay + ' 日</font><br>' +
         '<font color="yellow">' + cld[d].cYear + '年 ' + cld[d].cMonth + '月 ' + cld[d].cDay + '日</font>' +
         '</FONT></TD></TR></TABLE>' + festival + '</TD></TR></TABLE>';


        document.all["detail"].innerHTML = s;

        if (snow == 0) {
            dStyle.left = x - offsetx - width;
            dStyle.top = y + offsety - width;
            //dStyle.left = x;
            //dStyle.top = y;
            dStyle.visibility = "visible";

            snow = 1;
        }
    }
}
//清除详细日期资料
function mOut() {

    if (cnt >= 1) { sw = 0 }

    if (sw == 0) { snow = 0; dStyle.visibility = "hidden"; }
    else cnt++;
}
//取得位置
function mEvn() {
    if (m_bShowDetail == false) return;
    x = event.x;
    y = event.y;
    if (document.body.scrollLeft)
    { x = event.x - document.body.scrollLeft; y = event.y - document.body.scrollTop; }
    if (snow) {
        dStyle.left = x - offsetx - width;
        dStyle.top = y + offsety - width;
        //dStyle.left = x;
        //dStyle.top = y;
    }
}
///////////////////////////////////////////////////////////////////////////
function setCookie(name, value) {
    var today = new Date()
    var expires = new Date()
    expires.setTime(today.getTime() + 1000 * 60 * 60 * 24 * 365)
    document.cookie = name + "=" + escape(value) + "; expires=" +

expires.toGMTString()
}
function getCookie(Name) {
    var search = Name + "="
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) {
            offset += search.length
            end = document.cookie.indexOf(";", offset)
            if (end == -1) end = document.cookie.length
            return unescape(document.cookie.substring(offset, end))
        }
        else return ""
    }
}
/////////////////////////////////////////////////////////

var m_sDefaultCalendar = "标准日历";
/*
*为支持工作日配置功能，实现了下面以“GeoWD”开头的代码
*Creator:Wangshun 
*Creation Date:2006/10/20
*Modifier:
*Modify Date:
*/
function GeoWD_OnInit(DefaultCalXML) {
    //某一日期的详细信息，暂时不显示
    var detailDiv = document.getElementById("detail");
    dStyle = detailDiv.style;

    var yearSelect = document.getElementById("SY");
    yearSelect.selectedIndex = tY - 1900;
    var monthSelect = document.getElementById("SM");
    monthSelect.selectedIndex = tM;
    //当前年和月
    m_iCurYear = tY;
    m_iCurMonth = tM + 1;

    //	GeoWD_CreateDOMObjects();
    //	GeoWD_InitDOMObjects();
    //GeoWD_GetMonthWorkDayInfo(null,tY,tM+1,false,"INITIAL");
    m_ResponseXML = new ActiveXObject("MSXML2.DOMDOCUMENT.6.0");
    m_ResponseXML.loadXML(DefaultCalXML);

    //GeoWD_AppendResponseToDefaultXML();
    //GeoWD_InitCalendarNames();

    var NamesSelect = document.getElementById("CalendarNames");

    m_sCurrentCalendar = NamesSelect.value;
    //向日期单元格中写日期，其内容包括阴阳历日期、节日、节气等
    //在写的过程中，将从m_ResponseXML中获取工作日信息以设置日期单元格
    //的状态
    drawCld(tY, tM);

}

function GeoWD_CreateDOMObjects() {
    //初始化本文件中用到的所有XMLDOMDocument对象
    m_xmlDefaultInfo = new ActiveXObject("MSXML2.DOMDOCUMENT.6.0");
    m_xmlUpdateInfo = new ActiveXObject("MSXML2.DOMDOCUMENT.6.0");
    m_xmlUpdatedCells = new ActiveXObject("MSXML2.DOMDOCUMENT.6.0");
}
function GeoWD_InitDOMObjects() {
    m_xmlUpdatedCells.loadXML("<UpdateCells></UpDateCells>");

    var sDefaultXML = '<?xml version="1.0" encoding="utf-8"?>' +
	                            '<Calendars></Calendars>';
    m_xmlUpdateInfo.loadXML(sDefaultXML);
    m_xmlDefaultInfo.loadXML(sDefaultXML);
}
function GeoWD_GetMonthWorkDayInfo(sName, Year, Month, bAsynch, sAction, ReadyStateHandler) {
    ShowProgressBar("获取" + Year + "年" + Month + "月的日历信息...");
    var sQueryString = GeoWD_CreateQueryString(sName, Year, Month);

    GeoWD_DoRequestUsingGET(sQueryString, bAsynch, sAction, ReadyStateHandler);
}
function GeoWD_OnCurCalendarChanged(oSource, oEvent) {
    var sCurCalendar = oSource.options[oSource.selectedIndex].text;
    oEvent = GeoWD_GetEvent(oEvent);

    GeoWD_OnSubmit();

    //GeoWD_InitDOMObjects();
    m_sCurrentCalendar = sCurCalendar;
    ShowProgressBar("正在获取工作日信息...");
    GeoWD_GetMonthWorkDayInfo(sCurCalendar, m_iCurYear, m_iCurMonth, false, "QUERY", OnCurCalendarChangedHandler);

    //GeoForm_Output(m_xmlDefaultInfo.xml); 
    drawCld(m_iCurYear, m_iCurMonth - 1);
}
function OnCurCalendarChangedHandler() {
    if (m_XMLHttp.readyState == 4) {
        if (m_XMLHttp.status == 200) {
            if (m_XMLHttp.responseXML) {
                var result = GeoWD_ParseResponseResult(m_XMLHttp.responseXML);
                if (result) {
                    m_ResponseXML = null;
                    if (m_ResponseXML == null) m_ResponseXML = new ActiveXObject("MSXML2.DOMDOCUMENT.6.0");
                    m_ResponseXML.loadXML(result);

                    m_bResponseOK = true;
                    drawCld(m_iCurYear, m_iCurMonth - 1);
                }
                HideProgressBar("就绪！");
            }


        }
        else {
            HideProgressBar("获得日历信息失败！");
        }
    }
}
function GeoWD_SetSelectedItem(sItem, sSelBoxName) {
    var CalendarSelect = document.getElementById(sSelBoxName);
    if (CalendarSelect == null) return;

    var oOptions = CalendarSelect.options;
    var i, oOption;
    var sText;
    for (i = 0; i < oOptions.length; i++) {
        oOption = oOptions[i];
        sText = oOption.text;
        if (sText.toLowerCase() == sItem.toLowerCase()) {
            oOption.selected = true;
            break;
        }
    }
}
function GeoWD_InitCalendarNames() {
    if (m_bResponseOK == true) {
        var sXPath = "Calendars/CalendarNames";
        var NamesNode = m_ResponseXML.selectSingleNode(sXPath);
        var sCalendarNames = null;
        var sCurName = m_ResponseXML.documentElement.getAttribute("name");

        if (NamesNode != null) {
            sCalendarNames = NamesNode.text;
            var asNames = sCalendarNames.split(";");
            var CalendarSelect = document.getElementById("CalendarNames");
            CalendarSelect.innerHTML = "";

            var oOption = null;
            var sName = null;
            for (var i = 0; i < asNames.length; i++) {
                sName = asNames[i];
                oOption = document.createElement("OPTION");
                oOption.text = sName;
                if (sName == m_sDefaultCalendar) oOption.selected = true;
                CalendarSelect.add(oOption);
            }

            m_sCurrentCalendar = m_sDefaultCalendar;
        }
    }
}
function GeoWD_CreateQueryString(sName, sY, sM) {
    var sQueryString;

    //escape方法对 String 对象编码以便它们能在所有计算机上可读
    if (sName == null && sY != null && sM == null)
        sQueryString = "Year=" + escape(sY);
    else if (sName == null && sY == null && sM != null)
        sQueryString = "Month=" + escape(sM);
    else if (sName == null && sY != null && sM != null)
        sQueryString = "Year=" + escape(sY) + "&Month=" + escape(sM);
    else if (sName != null && sY == null && sM == null)
        sQueryString = "Name=" + escape(sName);
    else if (sName != null && sY != null && sM == null)
        sQueryString = "Name=" + escape(sName) + "&Year=" + escape(sY);
    else if (sName != null && sY != null && sM != null)
        sQueryString = "Name=" + escape(sName) + "&Year=" + escape(sY) + "&Month=" + escape(sM);


    return sQueryString;
}
function GeoWD_CreateXMLHttpRequest() {
    if (window.ActiveXObject) {
        m_XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        m_XMLHttp = new XMLHttpRequest();
    }
}
var iCounter = 0;
function GeoWD_DoRequestUsingGET(sQueryString, bAsynch, sAction, ReadyStateHandler) {
    GeoWD_CreateXMLHttpRequest();
    //默认为同步
    if (bAsynch == null) bAsynch = true;
    var sUrl = m_sResponseURL + "?" + sQueryString + "&timeStamp=" + new Date().getTime();

    if (sAction == null) sAction = "GET";
    sUrl += "&Action=" + sAction;

    m_bResponseOK = false;
    if (ReadyStateHandler)
        m_XMLHttp.onreadystatechange = ReadyStateHandler;
    else
        m_XMLHttp.onreadystatechange = GeoWD_HandleStateChange;

    iCounter++;
    sUrl += "&t=" + Math.random().toString();
    m_XMLHttp.open("GET", sUrl, bAsynch);
    m_XMLHttp.send(null);
}

function GeoWD_DoRequestUsingPOST(sQueryString, bAsynch, sAction, ReadyStateHandler) {
    GeoWD_CreateXMLHttpRequest();
    //默认为同步
    if (bAsynch == null) bAsynch = true;
    var sUrl = m_sResponseURL + "?timeStamp=" + new Date().getTime();
    //debugger;
    if (sAction == null) sAction = "GET";
    sUrl += "&Action=" + sAction;
    m_bResponseOK = false;

    m_XMLHttp.open("POST", sUrl, bAsynch);
    if (ReadyStateHandler)
        m_XMLHttp.onreadystatechange = ReadyStateHandler;
    else
        m_XMLHttp.onreadystatechange = GeoWD_HandleStateChange;
    m_XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");

    m_XMLHttp.send(sQueryString);
}

function GeoWD_HandleStateChange() {
    if (m_XMLHttp.readyState == 4) {
        if (m_XMLHttp.status == 200) {

            //m_ResponseXML=m_XMLHttp.responseXML;
            m_bResponseOK = true;
            HideProgressBar("就绪！");
            //GeoWD_AppendResponseToDefaultXML();
        }
        else {
            HideProgressBar("出现错误！");
        }
    }
}

function GeoWD_AppendResponseToDefaultXML() {
    //把从客户端返回来的结果m_ResponseXML合并到m_xmlDefaultInfo中，如果m_xmlDefaultInfo没有相关
    //日历的信息，那么直接添加，如果有，则删除原来的而后把m_ResponseXML中的信息添加进来

    var WorkDayInfosNodes = m_ResponseXML.selectNodes("Calendars/WorkDayInfos");
    var i, WorkDayInfosNode;
    var WorkDayInfosNode2;
    var NewNode;
    var sName = "";
    var docElement = m_xmlDefaultInfo.documentElement;

    for (i = 0; i < WorkDayInfosNodes.length; i++) {
        WorkDayInfosNode = WorkDayInfosNodes[i];
        sName = WorkDayInfosNode.getAttribute("name");

        WorkDayInfosNode2 = m_xmlDefaultInfo.selectSingleNode('Calendars/WorkDayInfos[@name="' + sName + '"]');

        //如果已经存在，删除
        if (WorkDayInfosNode2 != null)
            docElement.removeChild(WorkDayInfosNode2);

        var NewNode = GeoWD_CloneNode(m_xmlDefaultInfo, WorkDayInfosNode, true);
        docElement.appendChild(NewNode);
        //克隆一个过来
        //NewNode=WorkDayInfosNode.cloneNode(true);
        //docElement.appendChild(NewNode);
    }
}
var NODE_ELEMENT = 1;
var NODE_ATTRIBUTE = 2;
var NODE_TEXT = 3;
var NODE_CDATA_SECTION = 4;
var NODE_ENTITY_REFERENCE = 5;
var NODE_ENTITY = 6;
var NODE_PROCESSING_INSTRUCTION = 7;
var NODE_COMMENT = 8;
var NODE_DOCUMENT = 9;
var NODE_DOCUMENT_TYPE = 10;
var NODE_DOCUMENT_FRAGMENT = 11;
var NODE_NOTATION = 12;

function GeoWD_CloneNode(xmlDoc, oNode, deep) {
    Output(m_ResponseXML.xml);
    var oNewNode;
    if (deep == true) {
        var oNewNode;
        oNewNode = xmlDoc.createNode(oNode.nodeType, oNode.nodeName, oNode.namespaceURI);
        GeoWD_CopyAttributes(oNode, oNewNode);
        oNewNode = GeoWD_CreateNode(xmlDoc, oNode, oNewNode);
    }
    return oNewNode;
}

function GeoWD_CreateNode(xmlDoc, oNode, oNewNode) {
    var oNodeList = oNode.childNodes;
    var item, newItem;
    var oNewChildNode;
    for (var i = 0; i < oNodeList.length; i++) {
        item = oNodeList.item(i);

        newItem = xmlDoc.createNode(item.nodeType, item.nodeName, item.namespaceURI);
        oNewNode.appendChild(newItem);

        GeoWD_CopyAttributes(item, newItem);
        if (item.hasChildNodes == true) {
            oNewChildNode = GeoWD_CreateNode(xmlDoc, item, newItem);
        }
    }

    return oNewNode;
}
function GeoWD_CopyAttributes(oSourceNode, oTargetNode) {
    var oXMLDOMNamedNodeMap = oSourceNode.attributes;
    if (oXMLDOMNamedNodeMap == null) return;

    var i, oXMLDOMNode;
    var sText;
    for (i = 0; i < oXMLDOMNamedNodeMap.length; i++) {
        oXMLDOMNode = oXMLDOMNamedNodeMap.item(i);
        sText = oXMLDOMNode.text;
        if (sText != null && sText.length > 0)
            oTargetNode.setAttribute(oXMLDOMNode.nodeName, oXMLDOMNode.text);
    }
}

function GeoWD_OnMouseUp(oSource) {
    var sClassName = oSource.getAttribute("cellType");
    //如果cellType中包含了"WeekdayCell"，则说明该单元格
    //是周天单元格	
    if (sClassName.indexOf("WeekdayCell") > -1) {
        oSource.className = "WG5-Header";
    }
}
function GeoWD_OnMouseDown(oSource, oEvent) {
    document.selection.empty();
    if (oSource == null) return;

    //debugger;
    oEvent = GeoWD_GetEvent(oEvent);
    var bCtrlKey = oEvent.ctrlKey;
    //如果用户没有按下CTRL键，那么清除以前的选择
    if (bCtrlKey == false) GeoWD_ClearSelection();

    var sClassName = oSource.getAttribute("cellType");
    //如果cellType中包含了"WeekdayCell"，则说明该单元格
    //是周天单元格	
    if (sClassName.indexOf("WeekdayCell") > -1) {
        //说明该周天单元格被选择过，该属性在搜集工作日更新信息时用的到

        //如果用户选中某个周天单元格进行设置，那么说明该用户正在设置本
        //周天对应的工作日状态，比如设置周三为非工作日，那么该周天对应的
        //日期状态也应该被改变
        oSource.setAttribute("status", "selected");
        oSource.className = "OnMouseDown";
        var iWeekDayIndex = parseInt(oSource.getAttribute("WeekDayIndex"));
        var oDateCell;
        var num;
        //选中周天单元格的同时，也选中其对应（即与周天同列的）的日期单元格
        for (var i = 0; i < 6; i++) {
            num = iWeekDayIndex + i * 7;

            oDateCell = document.getElementById("GD" + num);

            GeoWD_SelectElement(oDateCell);
        }
    }
    //表明当前单击的单元格是日期单元格
    else if (sClassName.indexOf("DateCell") > -1) {
        //在用户按下ctrl键选择时，是多选
        if (bCtrlKey == true) {
            sId = oSource.id;
            if (m_allSelection.exists(sId) == true) {
                GeoWD_DeselectElement(oSource);
            }
            else
                GeoWD_SelectElement(oSource);
        }
        else
            GeoWD_SelectElement(oSource);
    }

    GeoWD_SetCtrlsState();
}

function GeoWD_SetCtrlsState() {
    //根据用户当前选择的日期来
    if (m_allSelection == null) return;
    if (m_allSelection.count < 1) return;

    var i, j, oDateCell, sDateCell;
    var iSelCount = m_allSelection.count;

    var arrayTemp = (new VBArray(m_allSelection.keys()));

    sDateCell = arrayTemp.getItem(0);
    oDateCell = m_allSelection.item(sDateCell);

    var bDayStateSame = true;
    var bTimeSame = true;
    var bAllSelUseDefault = true;
    var oDateCell2, sDateCell2;

    for (i = 0; i < iSelCount; i++) {
        sDateCell = arrayTemp.getItem(i);
        oDateCell = m_allSelection.item(sDateCell);
        j = i + 1;
        if (j > (iSelCount - 1)) break;
        sDateCell2 = arrayTemp.getItem(j);
        oDateCell2 = m_allSelection.item(sDateCell2);

        if (bAllSelUseDefault == true) {
            if ((oDateCell.getAttribute(m_csDayStateChanged) != oDateCell2.getAttribute(m_csDayStateChanged)) ||
			   (oDateCell.getAttribute(m_csWorkTimeChanged) != oDateCell2.getAttribute(m_csWorkTimeChanged)))
                bAllSelUseDefault = false;
        }

        if (bDayStateSame == true) {
            if (oDateCell.getAttribute("DayState") != oDateCell2.getAttribute("DayState"))
                bDayStateSame = false;
        }

        if (bTimeSame == true) {
            if (GeoWD_IsWorkTimeSame(oDateCell, oDateCell2) == false)
                bTimeSame = false;
        }
        //再比较就没有意义了，退出循环
        if (bDayStateSame == false && bTimeSame == false) break;
    }
    //如果用户选中的日期关于工作日设置的不同，就清除用户当前的选择，如果相同，就按照其中一个
    //DayState属性的值来设置控件状态
    if (bDayStateSame == true) {
        if (bAllSelUseDefault == true)
            GeoWD_SetWorkdayCtrlsState(oDateCell);
        else
            GeoWD_ClearWordRadioChecked();
    }
    else
        GeoWD_ClearWordRadioChecked();

    //所有选中控件的工作时段设置是否相同
    if (bTimeSame == true)
        GeoWD_SetWorkTimeCtrlsState(oDateCell);
    else
        GeoWD_ClearWorkTimeValue();
}

function GeoWD_SetWorkdayCtrlsState(oDateCell) {
    var sDayState, sDayStateChanged, sWorkTimeChanged;
    //获得工作日状态
    sDayState = oDateCell.getAttribute("DayState");

    sDayStateChanged = oDateCell.getAttribute(m_csDayStateChanged);
    sWorkTimeChanged = oDateCell.getAttribute(m_csWorkTimeChanged);

    if (sDayStateChanged == "false" && sWorkTimeChanged == "false") {
        if (sDayState == m_csPlayday) {
            GeoWD_ClearWorkTimeValue();
            GeoWD_SetWorkTimeInputsEnabled(false);
        }
        else if (sDayState = m_csWorkday)
            GeoWD_SetWorkTimeInputsEnabled(true);


        GeoWD_SetWorkdayRadioChecked("8");
    }
    else {
        if (sDayState == m_csPlayday) {
            GeoWD_SetWorkdayRadioChecked("4");
            GeoWD_ClearWorkTimeValue();
            GeoWD_SetWorkTimeInputsEnabled(false);
        }
        else if (sDayState = m_csWorkday) {

            GeoWD_SetWorkdayRadioChecked("2");
            GeoWD_SetWorkTimeInputsEnabled(true);
        }
    }
}
function GeoWD_GetUpdatedCells(Year, Month) {
    //保存所有被改变了的日期单元格的状态
    var docElement = m_xmlUpdatedCells.documentElement;
    if (docElement == null) {
        docElement = m_xmlUpdatedCells.createElement("UpdatedCells");
        m_xmlUpdatedCells.appendChild(docElement);
    }
    var oDateCellNode;
    var sXPath;
    for (var i = 0; i < 42; i++) {
        gObj = eval("GD" + i);
        if (GeoWD_IsValidDateCell(gObj) == true) {
            //获得天
            sObj = eval("SD" + i);
            sDay = sObj.innerHTML;
            if (GeoWD_IsDateCellChanged(gObj) == true) {
                sXPath = './DateCell[@Date="' + Year + "-" + Month + "-" + sDay + '"]';
                oDateCellNode = docElement.selectSingleNode(sXPath);
                if (oDateCellNode == null) {
                    oDateCellNode = m_xmlUpdatedCells.createElement("DateCell");
                    oDateCellNode.setAttribute("Date", Year + "-" + Month + "-" + sDay);
                    docElement.appendChild(oDateCellNode);
                }

                GeoWD_SaveDayStates(oDateCellNode, gObj);
                GeoWD_SaveWorkTimes(oDateCellNode, gObj);
            }
        }
    }

}

function GeoWD_SaveDayStates(oDateCellNode, DateCell) {
    oDateCellNode.setAttribute("DefaultDayState", DateCell.getAttribute("DefaultDayState"));
    oDateCellNode.setAttribute("DayState", DateCell.getAttribute("DayState"));
    oDateCellNode.setAttribute(m_csDayStateChanged, DateCell.getAttribute(m_csDayStateChanged));
    oDateCellNode.setAttribute(m_csWorkTimeChanged, DateCell.getAttribute(m_csWorkTimeChanged));
    oDateCellNode.setAttribute("OldBgColor", DateCell.getAttribute("OldBgColor"));
}

function GeoWD_RemoveDateCell(SY, SM, SD) {
    if (m_xmlUpdatedCells == null) return;
    var docElement = m_xmlUpdatedCells.documentElement;
    if (docElement == null) return;
    var sXPath = './DateCell[@Date="' + SM + "-" + SM + "-" + SD + '"]';
    var DateCellNode = docElement.selectSingleNode(sXPath);
    if (DateCellNode != null) docElement.removeChild(DateCellNode);

}
function GeoWD_SaveWorkTimes(oDateCellNode, DateCell) {
    var sBeginTime, sEndTime;
    var sDefaultBeginTime, sDefaultEndTime;
    var sBeginValue, sEndValue;
    var sDefaultBeginValue, sDefaultEndValue;
    var i;
    for (i = 1; i < 6; i++) {
        sBeginTime = "BeginTime" + i;
        sEndTime = "EndTime" + i;
        sDefaultBeginTime = "DefaultBeginTime" + i;
        sDefaultEndTime = "DefaultEndTime" + i;

        sBeginValue = DateCell.getAttribute(sBeginTime);
        sEndValue = DateCell.getAttribute(sEndTime);

        if (sBeginValue != null) oDateCellNode.setAttribute(sBeginTime, sBeginValue);
        if (sEndValue != null) oDateCellNode.setAttribute(sEndTime, sEndValue);

        sDefaultBeginValue = DateCell.getAttribute(sDefaultBeginTime);
        sDefaultEndValue = DateCell.getAttribute(sDefaultEndTime);

        if (sDefaultBeginValue != null) oDateCellNode.setAttribute(sDefaultBeginTime, sDefaultBeginValue);
        if (sDefaultEndValue != null) oDateCellNode.setAttribute(sDefaultEndTime, sDefaultEndValue);
    }

}
function GeoWD_ResetDayStates(DateCell, oDateCellNode) {
    var sDayState = oDateCellNode.getAttribute("DayState");
    var sWTChanged = oDateCellNode.getAttribute(m_csWorkTimeChanged);

    DateCell.setAttribute("DefaultDayState", oDateCellNode.getAttribute("DefaultDayState"));
    DateCell.setAttribute("DayState", oDateCellNode.getAttribute("DayState"));
    DateCell.setAttribute(m_csDayStateChanged, oDateCellNode.getAttribute(m_csDayStateChanged));
    DateCell.setAttribute(m_csWorkTimeChanged, sWTChanged);
    DateCell.setAttribute("OldBgColor", oDateCellNode.getAttribute("OldBgColor"));

    /*if(sDayState=="Workday")
    oDateCell.setAttribute("OldBgColor",oDateCellNode.getAttribute("OldBgColor"));
    else if(sDayState=="Playday")
    oDateCell.setAttribute("OldBgColor",oDateCellNode.getAttribute("OldBgColor"));*/

    if (sDayState == "Playday")
        DateCell.style.backgroundColor = m_PlaydayColor;
    else if (sDayState = "Workday")
        DateCell.style.backgroundColor = m_WorkdayColor;


    if (sWTChanged == "true")
        GeoWD_SetWTChangedStyle(DateCell);
    else
        GeoWD_ClearWTChangedStyle(DateCell);
}
function GeoWD_ResetWorkTimes(DateCell, oDateCellNode) {
    var sBeginTime, sEndTime;
    var sDefaultBeginTime, sDefaultEndTime;
    var sBeginValue, sEndValue;
    var sDefaultBeginValue, sDefaultEndValue;
    var i;
    for (i = 1; i < 6; i++) {
        sBeginTime = "BeginTime" + i;
        sEndTime = "EndTime" + i;
        sDefaultBeginTime = "DefaultBeginTime" + i;
        sDefaultEndTime = "DefaultEndTime" + i;

        sBeginValue = oDateCellNode.getAttribute(sBeginTime);
        sEndValue = oDateCellNode.getAttribute(sEndTime);

        if (sBeginValue != null) DateCell.setAttribute(sBeginTime, sBeginValue);
        if (sEndValue != null) DateCell.setAttribute(sEndTime, sEndValue);

        sDefaultBeginValue = oDateCellNode.getAttribute(sDefaultBeginTime);
        sDefaultEndValue = oDateCellNode.getAttribute(sDefaultEndTime);

        if (sDefaultBeginValue != null) DateCell.setAttribute(sDefaultBeginTime, sDefaultBeginValue);
        if (sDefaultEndValue != null) DateCell.setAttribute(sDefaultEndTime, sDefaultEndValue);
    }

}

function GeoWD_GatherUpdates(Year, Month) {
    //搜集界面上当前月份中被修改的工作日的相关数据
    //先获得当前的年份和月份
    var sXPath;
    var sObj, gObj, sDay;
    var IsValid;
    var WorkDayNode;
    var WorkDayInfoNode;
    var sDayState;
    var Weekday;

    var weekdayTR = document.getElementById("CalendarHeader");
    var weekdayTDs = weekdayTR.childNodes;
    var weekdayTD = null;
    var sStatus = null;
    var sOldWeekdayState = null;
    for (var j = 0; j < weekdayTDs.length; j++) {
        weekdayTD = weekdayTDs[j];
//        if (!weekdayTD.hasOwnProperty("status")) {
//            continue;
//        }
        sStatus = weekdayTD.getAttribute("status");
        if (sStatus == "selected") {

            sDayState = IsAllWeekdayDTCellChanged(weekdayTD);
            if (sDayState != "false") {
                var iWeekDayIndex = parseInt(weekdayTD.getAttribute("WeekDayIndex"));
                WorkDayNode = GetWorkDayInfoNode(null, null, null, iWeekDayIndex);
                sOldWeekdayState = WorkDayNode.getAttribute("State");
                SetWorkdayInfoAttr(WorkDayNode, null, null, null, iWeekDayIndex, sDayState);


                SetAllWeekdyDTProcess(weekdayTD, sOldWeekdayState);
            }
        }
    }
    for (var i = 0; i < 42; i++) {
        gObj = eval("GD" + i);
        var bProcess = gObj.getAttribute("process");
        if (bProcess != "true") {
            if (GeoWD_IsValidDateCell(gObj) == true) {
                //获得天
                sObj = eval("SD" + i);
                sDay = sObj.innerHTML;
                Weekday = GetWeekDayByCellIndex(i);
                //如果工作日的相关标识指明了关于该工作日的信息已经被改变，那么就保存该工作日的信息
                if (GeoWD_IsDateCellChanged(gObj) == true) {
                    sDayState = gObj.getAttribute("DayState");

                    WorkDayNode = GetWorkDayInfoNode(Year, Month, sDay, Weekday);
                    SetWorkdayInfoAttr(WorkDayNode, Year, Month, sDay, null, sDayState);
                }
                else {
                    //if(WorkDayNode!=null) GeoWD_RemoveWorkDayNode(WorkDayNode);
                }
            }
        }
    }

    var rootNode = m_ResponseXML.documentElement;
    if (rootNode) {
        rootNode.setAttribute("name", m_sCurrentCalendar);
        rootNode.setAttribute("year", Year);
        rootNode.setAttribute("month", Month);
    }

}

function SetWorkdayInfoAttr(WorkDayNode, Year, Month, Day, Weekday, DayState) {
    if (WorkDayNode == null) {
        WorkDayNode = m_ResponseXML.createElement("info");
        var rootNode = m_ResponseXML.documentElement;
        if (Month) {
            WorkDayNode.setAttribute("BeginDT", Year.toString() + "-" + Month.toString() + "-" + Day);
            WorkDayNode.setAttribute("EndDT", Year.toString() + "-" + Month.toString() + "-" + Day);
        }
        else {
            WorkDayNode.setAttribute("Weekday", Weekday);
        }
        rootNode.appendChild(WorkDayNode);
    }
    else {
        if (Month) {
            WorkDayNode.setAttribute("BeginDT", Year.toString() + "-" + Month.toString() + "-" + Day);
            WorkDayNode.setAttribute("EndDT", Year.toString() + "-" + Month.toString() + "-" + Day);
        }
        else {
            WorkDayNode.setAttribute("Weekday", Weekday);
        }
    }

    if (DayState == m_csPlayday) {
        WorkDayNode.setAttribute("State", "2");
    }
    else {
        WorkDayNode.setAttribute("State", "1");
    }
}
function SetAllWeekdyDTProcess(weekdayTD, sOldWeekayState) {
    var iWeekDayIndex = parseInt(weekdayTD.getAttribute("WeekDayIndex"));
    if (sOldWeekayState == "1")
        sOldWeekayState = m_csWorkday;
    else
        sOldWeekayState = m_csPlayday;
    var oDateCell;
    var num;
    var sOldDayState = "";
    var sDayState = "";
    for (var i = 0; i < 6; i++) {
        num = iWeekDayIndex + i * 7;

        oDateCell = document.getElementById("GD" + num);
        sOldDayState = oDateCell.getAttribute("OldDayState");
        if (sOldDayState == sOldWeekayState)
            oDateCell.setAttribute("process", "true");
    }
}
function IsAllWeekdayDTCellChanged(weekdayTD) {
    //某个周天对应的日期是否都已经被改变过
    var iWeekDayIndex = parseInt(weekdayTD.getAttribute("WeekDayIndex"));
    var oDateCell;
    var num;
    var sOldDayState = "";
    var sDayState = "";
    var iCounter = 0;
    for (var i = 0; i < 6; i++) {
        num = iWeekDayIndex + i * 7;

        oDateCell = document.getElementById("GD" + num);
        if (GeoWD_IsValidDateCell(oDateCell) == true) {
            sDayState = oDateCell.getAttribute("DayState");

            //		    if(GeoWD_IsDateCellChanged(oDateCell)==false) 
            //		    {
            //		        if(sDayState!=m_csPlayday) return "false";
            //		    }
            if (iCounter > 0) {
                if (sOldDayState != sDayState) return "false";
            }
            iCounter++;
            sOldDayState = sDayState;
        }
    }
    return sOldDayState;

}
function GeoWD_GetWorkTime(DateCell, WorkDayInfoNode) {
    var i;
    var sBeginTime, sEndTime;
    var sBeginValue, sEndValue;
    var sXPath;
    var WorkTimeNode;
    for (i = 1; i <= 5; i++) {
        sBeginTime = "BeginTime" + i;
        sEndTime = "EndTime" + i;

        sBeginValue = DateCell.getAttribute(sBeginTime);
        sEndValue = DateCell.getAttribute(sEndTime);

        if (sBeginValue != null && sBeginValue.length > 0) {
            sXPath = "./WorkTime[" + i + "]";
            WorkTimeNode = WorkDayInfoNode.selectSingleNode(sXPath);
            if (WorkTimeNode == null) {
                WorkTimeNode = m_xmlUpdateInfo.createElement("WorkTime");
                WorkDayInfoNode.appendChild(WorkTimeNode);
            }
            WorkTimeNode.setAttribute("BeginTime", sBeginValue);
            WorkTimeNode.setAttribute("EndTime", sEndValue);
        }
    }
}
function GeoWD_IsDateCellChanged(DateCell) {
    if ((DateCell.getAttribute(m_csDayStateChanged) == "true")) {
        return true;
    }
    return false;
}
function GeoWD_SetWorkTimeCtrlsState(oDateCell) {
    //获得工作日时段

    var i, oInput;
    var sBeginTime, sEndTime;
    var BeginTimeValue, EndTimeValue;
    for (i = 1; i <= 5; i++) {
        sBeginTime = "BeginTime" + i;
        sEndTime = "EndTime" + i;

        BeginTimeValue = oDateCell.getAttribute(sBeginTime);
        if (BeginTimeValue == null) BeginTimeValue = "";
        EndTimeValue = oDateCell.getAttribute(sEndTime);
        if (EndTimeValue == null) EndTimeValue = "";

        oInput = document.getElementById(sBeginTime);
        if (oInput != null) oInput.value = BeginTimeValue;
        oInput = document.getElementById(sEndTime);
        if (oInput != null) oInput.value = EndTimeValue;
    }
}

function GeoWD_OnWorkTimeChanged(oSource, oEvent) {
    if (m_allSelection == null) return;
    if (m_allSelection.count < 1) return;

    if (oSource == null) return;
    oEvent = GeoWD_GetEvent(oEvent);
    var sInputId = oSource.id;
    var sInputValue = oSource.value;

    var arrayTemp = (new VBArray(m_allSelection.items())).toArray();
    var i, oDateCell;
    for (i in arrayTemp) {
        oDateCell = arrayTemp[i];
        oDateCell.setAttribute(sInputId, sInputValue);
        if (oDateCell.getAttribute("DayState") == m_csPlayday) {
            GeoWD_SetDateCellByWorkDay(oDateCell);
        }
        if (GeoWD_IsWTChanged(oDateCell, sInputValue, sInputId) == false) {
            oDateCell.setAttribute(m_csWorkTimeChanged, "true");
            GeoWD_SetWTChangedStyle(oDateCell);
        }
        else {
            oDateCell.setAttribute(m_csWorkTimeChanged, "false");
            GeoWD_ClearWTChangedStyle(oDateCell);
        }
    }
    //只要用户设置了工作时段，那么就认为当前选中的所有的日期已经变成了工作日
    GeoWD_SetWorkdayRadioChecked("2");
}

function GeoWD_IsWTChanged(DateCell, sTime, sTimeSection) {
    //The "WT" means "WorkTime"
    var sBeginTime, sEndTime;
    var sDBeginTime, sDEndTime; //The "D" means "Default"
    var i;
    if (GeoWD_IsDefaultWT(DateCell, sTime, sTimeSection) == true) {
        for (i = 1; i < 6; i++) {
            sBeginTime = "BeginTime" + i;
            sEndTime = "EndTime" + i;
            sDBeginTime = "DefaultBeginTime" + i;
            sDEndTime = "DefaultEndTime" + i;

            if (DateCell.getAttribute(sBeginTime) != DateCell.getAttribute(sDBeginTime) ||
				 DateCell.getAttribute(sEndTime) != DateCell.getAttribute(sDEndTime)) {
                return true;
            }
        }
    }
    return false;
}
function GeoWD_IsDefaultWT(DateCell, sTime, sTimeSection) {
    sTimeSection = "Default" + sTimeSection;
    if (DateCell.getAttribute(sTimeSection) == sTime)
        return true;
    return false;
}
function GeoWD_SetWTChangedStyle(DateCell) {
    DateCell.style.textDecorationUnderline = true;
    DateCell.style.fontStyle = "italic";
}

function GeoWD_ClearWTChangedStyle(DateCell) {
    DateCell.style.textDecorationUnderline = false;
    DateCell.style.fontStyle = "normal";
}

function ShowProgressBar(prompt) {
    var oprompt = document.getElementById("progressPrompt");
    var prgBarImg = document.getElementById("progressImg");
    oprompt.innerHTML = prompt;
    prgBarImg.style.display = "";
}
function HideProgressBar(prompt) {
    var prgBarImg = document.getElementById("progressImg");
    var oprompt = document.getElementById("progressPrompt");
    oprompt.innerHTML = prompt;
    prgBarImg.style.display = "none";
}
function GeoWD_OnSubmit() {
    debugger;
    //保存工作日更新信息
    GeoWD_SaveUpdates();
    //保存完毕后，应该将所有的日历格属性设置为“未修改”的状态
    GeoWD_ClearChangedState();
}
function GeoWD_ClearChangedState() {
    var sXPath;
    var sObj, gObj, sDay;
    var IsValid;
    var WorkDayNode;
    var WorkDayInfoNode;
    var sDayState;
    //var CurWorkDayInfosNode=GeoWD_GetCurWorkdayInfosNode();
    for (var i = 0; i < 42; i++) {
        gObj = eval("GD" + i);
        if (GeoWD_IsValidDateCell(gObj) == true) {
            //gObj.setAttribute(m_csWorkTimeChanged,"false");
            gObj.setAttribute(m_csDayStateChanged, "false");
            gObj.setAttribute("DefaultDayState", gObj.getAttribute("DayState"));
            gObj.setAttribute("process", "false");
            //GeoWD_ReplaceDefaultWT(gObj);

        }
    }
}
function GeoWD_ReplaceDefaultWT(DateCell) {
    var sBeginTime, sEndTime, j;
    var sDefaultBeginTime, sDefaultEndTime;
    var sBeginValue, sEndValue;
    for (var i = 1; i < 6; i++) {
        sBeginTime = "BeginTime" + i;
        sEndTime = "EndTime" + i;
        sDefaultBeginTime = "DefaultBeginTime" + i;
        sDefaultEndTime = "DefaultEndTime" + i;

        sBeginValue = DateCell.getAttribute(sBeginTime);
        sEndValue = DateCell.getAttribute(sEndTime);
        if (sBeginValue != null && sBeginValue.length > 0) {
            DateCell.setAttribute(sDefaultBeginTime, sBeginValue);
            DateCell.setAttribute(sDefaultEndTime, sEndValue);
        }
        else {
            DateCell.removeAttribute(sDefaultBeginTime);
            DateCell.removeAttribute(sDefaultEndTime);
        }

    }
}
function GeoWD_SaveUpdates() {

    GeoWD_GatherUpdates(m_iCurYear, m_iCurMonth);

    var sQueryString = "Data=" + escape(m_ResponseXML.xml);
    ShowProgressBar("正在保存数据...");
    GeoWD_DoRequestUsingPOST(sQueryString, false, "SAVE");
}
function GeoWD_GetCurWorkdayInfosNode() {
    var CurWorkDayInfosNode = m_xmlUpdateInfo.selectSingleNode('Calendars/WorkDayInfos[@name="' + m_sCurrentCalendar + '"]');
    if (CurWorkDayInfosNode == null) {
        CurWorkDayInfosNode = m_xmlUpdateInfo.createElement("WorkDayInfos");
        CurWorkDayInfosNode.setAttribute("name", m_sCurrentCalendar);
        m_xmlUpdateInfo.documentElement.appendChild(CurWorkDayInfosNode);
    }

    return CurWorkDayInfosNode;
}
function GeoWD_OnWorkTimeBlur(oSource, oEvent) {
    //TODO:此处添加错误判断代码
}
function GeoWD_IsWorkTimeSame(DateCell1, DateCell2) {
    var i, sBeginTime, sEndTime;
    var bSame = true;
    for (i = 1; i <= 5; i++) {
        sBeginTime = "BeginTime" + i;
        sEndTime = "EndTime" + i;

        if ((DateCell1.getAttribute(sBeginTime) != DateCell2.getAttribute(sBeginTime)) ||
      	   (DateCell1.getAttribute(sEndTime) != DateCell2.getAttribute(sEndTime))) {
            bSame = false;
            break;
        }
    }

    return bSame;
}
function GeoWD_SetWorkdayRadioChecked(sValue) {
    var OptionObject;
    var WorkDayInpus = document.getElementsByName("WorkDay");
    for (var i = 0; i < WorkDayInpus.length; i++) {
        OptionObject = WorkDayInpus[i];
        if (OptionObject.value == sValue)
            OptionObject.checked = true;
    }
}
function GeoWD_ClearWordRadioChecked() {
    var OptionObject;
    var WorkDayInpus = document.getElementsByName("WorkDay");
    for (var i = 0; i < WorkDayInpus.length; i++) {
        OptionObject = WorkDayInpus[i];
        OptionObject.checked = false;
    }
}
function GeoWD_ClearWorkTimeValue() {
    var WorkTimeInputs = document.getElementsByName("WorkTime");
    var oInput;
    for (var i = 0; i < WorkTimeInputs.length; i++) {
        oInput = WorkTimeInputs[i];
        oInput.value = "";
    }
}
function GeoWD_SetWorkTimeInputsEnabled(bEnabled) {
    var WorkTimeInputs = document.getElementsByName("WorkTime");
    var oInput;
    for (var i = 0; i < WorkTimeInputs.length; i++) {
        oInput = WorkTimeInputs[i];
        oInput.disabled = (!bEnabled);
    }
}

function GeoWD_IsIE() {
    if (document.all) return true;
    return false;
}
function GeoWD_GetEvent(oEvent) {
    if (oEvent == null) {
        return window.event;
    }
    else {
        return oEvent;
    }
}

var m_allSelection;                 //被选中的所有的日期单元格
function GeoWD_ClearSelection() {
    if (m_allSelection == null) return;

    var i, oEleSelected;
    var arrayTemp = (new VBArray(m_allSelection.items())).toArray();
    for (i in arrayTemp) {
        oEleSelected = arrayTemp[i];
        if (oEleSelected != null) {
            GeoWD_DeselectElement(oEleSelected);
        }
    }
}

function GeoWD_SelectElement(oElement) {
    if (oElement == null) return;

    if (GeoWD_IsValidDateCell(oElement) == false) return;
    //判断一个元素是否已经被选中
    if (GeoWD_IsElementSelected(oElement) == false) {
        var sOldColor = oElement.style.backgroundColor;

        if (sOldColor == null) sOldColor = "#FFFFFF";
        oElement.setAttribute("OldBgColor", sOldColor);

        oElement.style.backgroundColor = m_SelectItemColor;
        //标识元素已经被选中
        oElement.setAttribute("IsSelected", "true");
        //
        if (m_allSelection == null) m_allSelection = new ActiveXObject("Scripting.Dictionary");
        var sId = oElement.id;
        if (m_allSelection.exists(sId) == false) {
            m_allSelection.add(sId, oElement);
        }
    }

}

function GeoWD_IsClassUsed(OriName, sName) {
    var sParts = OriName.split(" ");
    var sPart;
    for (var i = 0; i < sParts.length; i++) {
        sPart = sParts[i];
        if (sName.toLowerCase() == sPart.toLowerCase()) {
            return true;
        }
    }

    return false;

}
function GeoWD_TrimClassName(OriginalName, NameTrimmed) {
    if (OriginalName == null) return null;
    if (NameTrimmed == null) return OriginalName;
    if (NameTrimmed.length < 1) return OriginalName;

    var sParts = OriginalName.split(" ");
    var sPart;
    var sNewClassName = "";
    for (var i = 0; i < sParts.length; i++) {
        sPart = sParts[i];
        if (NameTrimmed.toLowerCase() != sPart.toLowerCase()) {
            sNewClassName += " " + sPart;
        }
    }

    return sNewClassName;
}

function GeoWD_IsValidDateCell(DateCell) {

    //判断日期单元格中是否有日期信息，如果有视为“有效”
    var sValidDateCell = DateCell.getAttribute("ValidDateCell");

    if (sValidDateCell != null && sValidDateCell == "true")
        return true;
    else
        return false;

}

var BeginX, BeginY;
var EndX, EndY;
function GeoWD_OnMouseDownCalendarBody(oSource, oEvent) {
    document.selection.empty();

    oEvent = GeoWD_GetEvent(oEvent);

    var iButton = oEvent.button;
    if (iButton == 1) {
        //oEvent.returnValue=false;
        //oEvent.cancelBubble=true;

        BeginX = oEvent.clientX;
        BeginY = oEvent.clientY;
    }
}

function GeoWD_OnMouseMoveCalendarBody(oSource, oEvent) {
    document.selection.empty();

    oEvent = GeoWD_GetEvent(oEvent);
    oEvent.returnValue = false;

    var iButton = oEvent.button;
    var i, oDateCell;
    var bCtrlKey = oEvent.ctrlKey;
    if (iButton == 1) {
        //oEvent.returnValue=false;
        //oEvent.cancelBubble=true;
        EndX = oEvent.clientX;
        EndY = oEvent.clientY;

        var dicDateCells = GeoWD_GetDateCells(BeginX, BeginY, EndX, EndY);
        if (dicDateCells == null) return;

        if (m_allSelection == null) {

            GeoWD_SelectElementsInDic(dicDateCells);
        }
        else {
            /*
            *拿dicDateCells中的元素与已经选中的元素做比较，如果dicDateCells中不存在那个已经选中的元素，并且
            *此时用户没有按下Ctrl键，那么就把该元素反选调；对于dicDateCells中存在的已经选中的元素，直接删除
            *以便下一步遍历选择那些其中未被选中的元素
            */
            var sDateCellId;
            var arrayTemp = (new VBArray(m_allSelection.items())).toArray();

            for (i in arrayTemp) {
                oDateCell = arrayTemp[i];
                if (oDateCell != null) {
                    sDateCellId = oDateCell.id;
                    if (dicDateCells.Exists(sDateCellId) == false) {
                        if (bCtrlKey == false) {
                            GeoWD_DeselectElement(oDateCell);
                        }
                    }
                    else {
                        //删除其中已经选中的元素
                        dicDateCells.Remove(sDateCellId);
                    }
                }
            }
            //遍历选择剩余的元素
            GeoWD_SelectElementsInDic(dicDateCells);
        }
    }
}

function GeoWD_OnMouseUpCalendarBody(oSource, oEvent) {
    GeoWD_SetCtrlsState();
}
function GeoWD_SelectElementsInDic(dicElements) {
    //选择存放在一个Dictionary对象中的所有元素
    var arrayTemp = (new VBArray(dicElements.items())).toArray();
    var i;
    var oDateCell;
    for (i in arrayTemp) {
        oDateCell = arrayTemp[i];

        GeoWD_SelectElement(oDateCell);
    }
}
function GeoWD_DeselectElement(oElement) {
    if (oElement != null) {

        //oElement.className=GeoWD_TrimClassName(oElement.className,"SelectedItem");

        var sOldBgColor = oElement.getAttribute("OldBgColor");

        if (sOldBgColor == null) sOldBgColor = "FFFFFF";

        oElement.style.backgroundColor = sOldBgColor;

        oElement.removeAttribute("IsSelected");

        var sId = oElement.id;
        if (m_allSelection.exists(sId) == true) m_allSelection.remove(sId);

    }
}

function GeoWD_IsElementSelected(oElement) {
    var sSelected = oElement.getAttribute("IsSelected");
    if (sSelected != null && sSelected == "true")
        return true;
    else
        return false;

}

function Output(sResult, Append) {
    var spanResult = document.getElementById("Coords");
    if (spanResult == null) return;

    if (Append == true)
        spanResult.innerText += "\t" + sResult;
    else
        spanResult.innerText = sResult;
}

function GeoWD_GetDateCells(BeginX, BeginY, EndX, EndY) {
    var CalendarBody = document.getElementById("CalendarBody");

    var dicDateCells = new ActiveXObject("Scripting.Dictionary");

    var oDateCell;
    var sDateCellId;

    var CellPos1 = GeoWD_GetDateCellByPos(BeginX, BeginY);
    var CellPos2 = GeoWD_GetDateCellByPos(EndX, EndY);

    var BeginRow = (CellPos1.Row >= CellPos2.Row) ? CellPos2.Row : CellPos1.Row;
    var EndRow = (CellPos1.Row <= CellPos2.Row) ? CellPos2.Row : CellPos1.Row;
    var BeginCol = (CellPos1.Col >= CellPos2.Col) ? CellPos2.Col : CellPos1.Col;
    var EndCol = (CellPos1.Col <= CellPos2.Col) ? CellPos2.Col : CellPos1.Col;

    if (BeginRow == -1 || EndRow == -1 || BeginCol == -1 || EndCol == -1) return null;

    var i, num;
    if (BeginRow == EndRow) {

        GeoWD_GetPreelectionCells(BeginCol, EndCol, BeginRow * 7, dicDateCells);

    }
    else if ((BeginRow + 1) == EndRow) {
        GeoWD_GetPreelectionCells(BeginCol, 6, BeginRow * 7, dicDateCells);
        GeoWD_GetPreelectionCells(0, EndCol, EndRow * 7, dicDateCells);
    }
    else if ((EndRow - BeginRow) > 1) {
        GeoWD_GetPreelectionCells(BeginCol, 6, BeginRow * 7, dicDateCells);

        for (i = 1; i < (EndRow - BeginRow); i++) {
            GeoWD_GetPreelectionCells(0, 6, (BeginRow + i) * 7, dicDateCells);
        }

        GeoWD_GetPreelectionCells(0, EndCol, EndRow * 7, dicDateCells);

    }
    return dicDateCells;
}
function GeoWD_GetPreelectionCells(LoopBegin, LoopEnd, IdBaseNum, dicDateCells) {
    var num;
    var sDateCellId, oDateCell;
    for (var i = LoopBegin; i <= LoopEnd; i++) {
        num = IdBaseNum + i
        sDateCellId = "GD" + num;
        oDateCell = eval(sDateCellId);
        if (dicDateCells.Exists(sDateCellId) == false) {
            dicDateCells.Add(sDateCellId, oDateCell);
        }
    }
}

function GeoWD_OnWorkdayRadioClick(oSource, oEvent) {
    if (m_allSelection == null) return;
    if (m_allSelection.count < 1) return;

    oEvent = GeoWD_GetEvent(oEvent);
    var iValue = parseInt(oSource.value);

    switch (iValue) {
        case 2:         //工作日	
            GeoWD_SetSelectionToWorkday();
            break;
        case 4:         //非工作日
            GeoWD_SetSelectionToPlayday();
            break;
        case 8:         //使用默认设置
            GeoWD_SetSelectionToDefault();
            break;
        default:
            break;
    }
}
function GeoWD_SetSelectionToDefault() {
    //设置为缺省意味着没有变化
    var arrayTemp = (new VBArray(m_allSelection.items())).toArray();
    var i, oDateCell;
    var sDayState;

    for (i in arrayTemp) {
        oDateCell = arrayTemp[i];
        GeoWD_ResetDateCellAttrs(oDateCell);

        sDayState = oDateCell.getAttribute("DayState");

        if (sDayState == "Workday")
            oDateCell.setAttribute("OldBgColor", m_WorkdayColor);
        else if (sDayState == "Playday")
            oDateCell.setAttribute("OldBgColor", m_PlaydayColor);

        GeoWD_RemoveDateCellInfo(oDateCell);
    }

    //GeoWD_SetCtrlsState();	

}

function GeoWD_RemoveDateCellInfo(DateCell) {
    if (m_xmlUpdatedCells == null) return;
    var docElement = m_xmlUpdatedCells.documentElement;
    if (docElement == null) return;

    var sDateValue = DateCell.getAttribute("DateValue");
    var sXPath = './DateCell[@Date="' + sDateValue + '"]';
    var DateCellNode = docElement.selectSingleNode(sXPath);
    if (DateCellNode != null) docElement.removeChild(DateCellNode);
}

function GeoWD_ResetDateCellAttrs(oDateCell) {
    //将变化标识属性设为false，表示关于该工作日的信息没有变化
    oDateCell.setAttribute(m_csDayStateChanged, "false");
    oDateCell.setAttribute(m_csWorkTimeChanged, "false");

    oDateCell.setAttribute("DayState", oDateCell.getAttribute("DefaultDayState"));
    var DefaultBeginTime, DefaultEndTime;
    var BeginTime, EndTime;
    for (var i = 1; i <= 5; i++) {
        DefaultBeginTime = "DefaultBeginTime" + i;
        DefaultEndTime = "DefaultEndTime" + i;
        BeginTime = "BeginTime" + i;
        EndTime = "EndTime" + i;

        oDateCell.setAttribute(BeginTime, oDateCell.getAttribute(DefaultBeginTime));
        oDateCell.setAttribute(EndTime, oDateCell.getAttribute(DefaultEndTime));
    }

}
function GeoWD_SetSelectionToWorkday() {
    var arrayTemp = (new VBArray(m_allSelection.items())).toArray();
    var i, oDateCell;
    var sDayState;

    for (i in arrayTemp) {
        oDateCell = arrayTemp[i];
        sDayState = oDateCell.getAttribute("DayState");

        if (sDayState == "Playday") {
            //oDateCell.style.backgroundColor=m_WorkdayColor;
            GeoWD_SetDateCellByWorkDay(oDateCell);

            //GeoWD_SetDefaultWorkTime(oDateCell);
            //GeoWD_SetWorkTimeCtrlsState(oDateCell);
            //GeoWD_SetWorkTimeInputsEnabled(true);
        }
    }

    //GeoWD_SetCtrlsState();
}
function GeoWD_SetDateCellByWorkDay(DateCell) {
    DateCell.setAttribute("OldBgColor", m_WorkdayColor);
    DateCell.setAttribute("DayState", m_csWorkday);
    DateCell.setAttribute(m_csDayStateChanged, "true");
}
function GeoWD_SetDefaultWorkTime(oDateCell) {
    var curWorkDayInfosNode = m_xmlDefaultInfo.selectSingleNode('Calendars/WorkDayInfos[@name="' + m_sCurrentCalendar + '"]');
    if (curWorkDayInfosNode) {
        var sXPath = './WorkDayInfo[not (WorkDay) and WorkTime]';
        var WorkInfoNodeTime = curWorkDayInfosNode.selectSingleNode(sXPath);
        GeoWD_SetWorkTimeByNode(oDateCell, WorkInfoNodeTime)
    }
    else {
        GeoWD_SetWorkTimeAttrs(oDateCell);
    }

}
function GeoWD_RemoveWorkDayNode(WorkDayNode) {
    var WorkDayInfoNode = WorkDayNode.parentNode;
    var sState = WorkDayNode.getAttribute("State");

    if (sState == "4" || sState == "2") {
        var sXPath = "./WorkDay";
        var WorkDayNodes = WorkDayInfoNode.selectNodes(sXPath);
        var iLength = WorkDayNodes.length;

        if (iLength > 1) {
            WorkDayInfoNode.removeChild(WorkDayNode);
        }
        else if (iLength == 1) {
            var WorkDayInfos = WorkDayInfoNode.parentNode;
            WorkDayInfos.removeChild(WorkDayInfoNode);
        }
    }
}
function GeoWD_SetSelectionToPlayday() {
    var arrayTemp = (new VBArray(m_allSelection.items())).toArray();
    var i, oDateCell;
    var sDayState;

    for (i in arrayTemp) {
        oDateCell = arrayTemp[i];
        sDayState = oDateCell.getAttribute("DayState");

        if (sDayState == "Workday") {
            //oDateCell.style.backgroundColor=m_WorkdayColor;
            oDateCell.setAttribute("OldBgColor", m_PlaydayColor);
            oDateCell.setAttribute("DayState", m_csPlayday);
            oDateCell.setAttribute(m_csDayStateChanged, "true");

            GeoWD_SetWorkTimeInputsEnabled(false);
        }
    }

    GeoWD_SetWorkTimeInputsEnabled(false);
    //GeoWD_SetCtrlsState();
}


function GeoWD_GetDateCellByPos(x, y) {
    var CellPos = { Row: -1, Col: -1 };
    var oDateCell;
    var left, top, right, bottom;
    var pos;
    for (var i = 0; i < 7; i++) {
        oDateCell = eval("GD" + i);
        pos = GeoWD_GetPos(oDateCell);
        left = pos.left;
        right = pos.left + oDateCell.clientWidth;

        if (left <= x && right >= x) {
            CellPos.Col = i;
            break;
        }
    }
    for (var i = 0; i < 6; i++) {
        num = 0 + i * 7;

        oDateCell = document.getElementById("GD" + num);
        pos = GeoWD_GetPos(oDateCell);
        top = pos.top;
        bottom = pos.top + oDateCell.clientHeight;

        if (top <= y && bottom >= y) {
            CellPos.Row = i;
            break;
        }
    }

    return CellPos;

}
function ShowCalendarBody() {
    var oTable = document.getElementById("CalendarBody");

}

function GeoWD_GetPos(element) {
    var pos = { left: 0, top: 0 };
    if (GeoWD_IsIE()) {
        var rect = element.getBoundingClientRect();
        //*********************
        // frameType
        // 0 : not in any frame
        // 1 : in the left frame
        // 2 : in the right frame
        // 3 : in the top frame
        // 4 : in the bottom frame
        // 5 : in the left-top frame
        // 6 : in the right-top frame
        // 7 : in the left-bottom frame
        // 8 : in the right-bottom frame
        // 9 : in an iframe
        //*********************
        var frameType = 0;
        var offsetX = 0;
        var offsetY = 0;
        if (frameType == 0) {
            offsetX = -2;
            offsetY = -2;
        } else if (frameType == 1) {
            offsetX = 0;
            offsetY = 0;
        } else if (frameType == 2) {
            offsetX = -2;
            offsetY = 0;
        } else if (frameType == 3) {
            offsetX = 0;
            offsetY = 0;
        } else if (frameType == 4) {
            offsetX = 0;
            offsetY = -2;
        } else if (frameType == 5) {
            offsetX = 0;
            offsetY = 0;
        } else if (frameType == 6) {
            offsetX = -2;
            offsetY = 0;
        } else if (frameType == 7) {
            offsetX = 0;
            offsetY = -2;
        } else if (frameType == 8) {
            offsetX = -2;
            offsetY = -2;
        } else if (frameType == 9) {
            offsetX = -2;
            offsetY = -2;
        }
        pos.left = rect.left + offsetX + document.body.scrollLeft;
        pos.top = rect.top + offsetY + document.body.scrollTop;
    } else {
        GeoWD_GetPosByOffset(element, pos);
    }
    return pos;
}


function GeoWD_GetPosByOffset(element, pos) {
    pos.left += element.offsetLeft;
    pos.top += element.offsetTop;
    var parent = element.offsetParent;
    if (parent != null) {
        GeoWD_GetPosByOffset(parent, pos);
    }
}

function GeoWD_CreateCalendarHeader(headerTR) {
    //创建“周天”列
    var fontColor;
    var newTD = null;
    var newFont = null;
    for (var k = 0; k < 7; k++) {
        newTD = document.createElement("td");
        newTD.setAttribute("WeekDayIndex", k.toString());
        newTD.className = "WG5-Header";

        newTD.style.textAlign = "center";
        newTD.setAttribute("cellType", "WeekdayCell");
        newTD.style.cursor = "hand";
        newTD.onmousedown = function () { GeoWD_OnMouseDown(this, null); };
        newTD.onmouseup = function () { GeoWD_OnMouseUp(this); };
        //fontColor= GeoWD_GetFontColorByWeekDay(k);

        newFont = document.createElement("font");
        newFont.style.fontSize = "12px";
        newFont.style.fontWeight = "bold";
        //newFont.style.color=fontColor;

        newFont.innerText = GeoWD_GetWeekDayChByIndex(k);
        newTD.appendChild(newFont);
        newTD.style.textAlign = "center";
        headerTR.appendChild(newTD);
    }
}
function GeoWD_GetWeekDayChByIndex(iIndex) {
    switch (iIndex) {
        case 0: return "日";
        case 1: return "一";
        case 2: return "二";
        case 3: return "三";
        case 4: return "四";
        case 5: return "五";
        case 6: return "六";
    }
    return "一";

}
function GeoWD_GetFontColorByWeekDay(iIndex) {
    switch (iIndex) {
        case 0: return "red";
        case 6: return "green";
        default: return "black";
    }
    return "black";
}

function GeoWD_FillWorkdayGrid(calendarTable) {
    //日历体		
    var gNum
    var sWeekDay
    var newTR = null;
    var newTD = null;
    var newFont = null;
    var tableBody = GetTableBody(calendarTable);
    //行
    for (i = 0; i < 6; i++) {
        newTR = document.createElement("tr");
        newTR.id = "CalendarBody";
        newTR.onmouseup = function () { GeoWD_OnMouseUpCalendarBody(this, null); };
        newTR.onmousedown = function () { GeoWD_OnMouseDownCalendarBody(this, null); };
        newTR.onmousemove = function () { GeoWD_OnMouseMoveCalendarBody(this, null); };
        newTR.align = "center";
        newTR.style.borderWidth = "1";
        newTR.height = 33;
        //列
        for (j = 0; j < 7; j++) {
            gNum = i * 7 + j
            newTD = document.createElement("td");
            newTD.className = "DateCell";
            newTD.id = "GD" + gNum.toString();
            newTD.onmousedown = function () { GeoWD_OnMouseDown(this, null); };
            newTD.onmouseover = function () { mOvr(gNum); };
            newTD.onmouseout = function () { mOut(); };
            newTD.setAttribute("cellType", "DateCell");
            newTD.style.width = "300px";

            newFont = document.createElement("font");
            newFont.id = "SD" + gNum.toString();
            newFont.size = 2;
            newFont.style.fontSize = "9pt";

            newTD.appendChild(newFont);
            var newBR = document.createElement("br");
            newTD.appendChild(newBR);

            newFont = document.createElement("font");
            newFont.id = "LD" + gNum.toString();
            newFont.size = 2;
            newFont.style.fontSize = "9pt";
            newTD.appendChild(newFont);
            newTR.appendChild(newTD);
        }
        tableBody.appendChild(newTR);
    }
}
function GeoWD_GetWeekDayByIndex(iIndex) {
    switch (iIndex) {
        case 0: return "Sunday";
        case 1: return "Monday";
        case 2: return "Tuesday";
        case 3: return "Wednesday";
        case 4: return "Thursday";
        case 5: return "Friday";
        case 6: return "Saturday";
    }
    return "Monday";
}

var m_sNewName = null;
function GeoWD_OnCreateNewCalendar() {
    if (confirm("你确定要添加新日历吗？")) {
        var bConfirmed;

        GeoWD_GatherUpdates(m_iCurYear, m_iCurMonth);

        var sName = GeoWD_GetCurrentCalendarName();

        var argObject = GeoWD_ShowNewCalendarDlg();

        if (argObject == null) return;
        var sNewName = argObject.NewName;
        var sSourceName = argObject.SourceName;

        if (sNewName == null) return;
        if (sNewName.length < 1) return;

        GeoWD_OnSubmit();

        GeoWD_CreateCalendar(sNewName, sSourceName);

        m_argObject = null;
    }
}
function GeoWD_CreateCalendar(sNewName, sSourceName) {
    ShowProgressBar("正在请求服务器，创建日历");
    var sQueryString = "NewName=" + escape(sNewName) + "&SourceName=" + escape(sSourceName) + "&Year=" + escape(m_iCurYear) + "&Month=" + escape(m_iCurMonth);
    m_sNewName = sNewName;
    GeoWD_DoRequestUsingGET(sQueryString, false, "CREATE", CreateCalendarHandler);

    //drawCld(m_iCurYear,m_iCurMonth-1); 	
}
function CreateCalendarHandler() {
    if (m_XMLHttp.readyState == 4) {
        if (m_XMLHttp.status == 200) {

            if (m_XMLHttp.responseXML) {
                var result = GeoWD_ParseResponseResult(m_XMLHttp.responseXML);
                if (result) {
                    m_ResponseXML = null;
                    if (m_ResponseXML == null) m_ResponseXML = new ActiveXObject("MSXML2.DOMDOCUMENT.6.0");
                    m_ResponseXML.loadXML(result);

                    GeoWD_CreateNameOption(m_sNewName);
                    m_sCurrentCalendar = m_sNewName;
                    m_bResponseOK = true;
                    drawCld(m_iCurYear, m_iCurMonth - 1);
                }
                HideProgressBar("创建新日历成功！");
            }

        }
        else {
            HideProgressBar("创建新日历失败！");
        }
    }
}
function GeoWD_IsNodeExisted(xmlDoc, XPath) {
    var nodeTemp = xmlDoc.selectSingleNode(XPath);
    if (nodeTemp == null)
        return false;
    else
        return true;

}
function GetTableBody(otable) {
    var tableChildNodes = otable.childNodes;
    var node;
    for (var i = 0; i < tableChildNodes.length; i++) {
        node = tableChildNodes[i];
        if (node.tagName == undefined) {
            continue;
        }
        if (node.tagName.toLowerCase() == "tbody") {
            return node;
        }
    }
    return null;
}
function GeoWD_IsItemExsits(sItem, sSelBoxName) {
    var CalendarSelect = document.getElementById(sSelBoxName);
    if (CalendarSelect == null) return false;

    var oOptions = CalendarSelect.options;
    var i, oOption;
    var sText;
    for (i = 0; i < oOptions.length; i++) {
        oOption = oOptions[i];
        sText = oOption.text;
        if (sText.toLowerCase() == sItem.toLowerCase()) {
            return true;
        }
    }
    return false;
}
function GeoWD_CreateNameOption(sText, sValue) {
    var CalendarSelect = document.getElementById("CalendarNames");
    if (CalendarSelect == null) return false;

    var oOption = document.createElement("option");
    oOption.text = sText;
    if (sValue != null)
        oOption.value = sValue;

    CalendarSelect.add(oOption);
    oOption.selected = true;
}
function GeoWD_GetCurrentCalendarName() {
    //获得用户当前选中的日历的名称
    var CalendarSelect = document.getElementById("CalendarNames");
    if (CalendarSelect == null) return null;

    var sName = CalendarSelect.options[CalendarSelect.selectedIndex].text;
    return sName;
}

function GeoWD_GetCalendarNames() {
    var CalendarSelect = document.getElementById("CalendarNames");
    if (CalendarSelect == null) return null;

    var aNames = new Array();
    var oOptions = CalendarSelect.options;
    var i, oOption;
    var sText;
    for (i = 0; i < oOptions.length; i++) {
        oOption = oOptions[i];
        sText = oOption.text;
        aNames[aNames.length] = sText;
    }
    return aNames;
}

/*
*NOTE：THESE CODES FOLLOWING IMPLEMENT THE FUNCTIONS OF THE "CREATE CALENDAR" DIALOG
*CREATOR:WANGSHUN
*CREATION DATE: 2006/10/30
*/

var m_NewCalendarPage = "CreateCalendar.htm";

function GeoWD_ShowNewCalendarDlg() {
    var argObject = new Object();
    var curName = GeoWD_GetCurrentCalendarName();
    argObject.CalendarNames = GeoWD_GetCalendarNames();
    argObject.CurrentName = curName;
    argObject.NewName = "新日历";
    argObject.SourceName = curName;
    argObject.Ok = false;

    window.showModalDialog(m_NewCalendarPage, argObject, "dialogHeight:150pt;dialogWidth:240pt;help:no");

    var ResultObject = new Object();

    if (argObject.Ok == true) {
        var ResultObject = new Object();
        ResultObject.NewName = argObject.NewName;
        ResultObject.SourceName = argObject.SourceName;

        return ResultObject;
    }
    return null;
}

function GeoWD_InitDialog() {
    //Initialize the dialog 

    m_argObject = window.dialogArguments;
    var aNames = m_argObject.CalendarNames;
    var sDefaultName = m_argObject.NewName;
    var sCurrentName = m_argObject.CurrentName;

    var NameInput = document.getElementById("CalendarName");
    if (NameInput == null) return;
    NameInput.value = sDefaultName;

    var NamesSelect = document.getElementById("CalendarNames");
    if (NamesSelect == null) return;
    var sName = "";
    var oOption;

    for (var i = 0; i < aNames.length; i++) {
        sName = aNames[i];
        oOption = document.createElement("OPTION");
        oOption.text = sName;
        if (sName.toLowerCase() == sCurrentName.toLowerCase())
            oOption.selected = true;
        NamesSelect.add(oOption);
    }
}
function GeoWD_OnOK() {
    var sNewName = document.getElementById("CalendarName").value;
    if (sNewName != null && sNewName.length > 0) {
        if (GeoWD_IsItemExsits(sNewName, "CalendarNames") == false) {
            m_argObject.NewName = sNewName;
            var NameSelect = document.getElementById("CalendarNames");

            m_argObject.SourceName = NameSelect.options[NameSelect.selectedIndex].text;
            m_argObject.Ok = true;

            window.close();
        }
        else {
            alert("日历【" + sNewName + "】已经存在，请重新输入。");
        }
    }
    else {
        alert("请输入您要新建的日历的名称。");
    }
}
function GeoWD_OnCancel() {
    m_argObject.OK = false;
    window.close();
}
function GeoForm_Output(sResult, bAppend) {
    var empElement = document.getElementsByTagName("emp").item(0);
    if (empElement == null) {
        empElement = document.createElement("emp");
    }
    if (bAppend == true) {
        empElement.innerText = empElement.innerText + ":" + sResult;
    }
    else {
        empElement.innerText = sResult;
    }

    var OutputTd = document.getElementById("OutputTd");
    if (OutputTd) OutputTd.appendChild(empElement);

}